package com.member.web.controller.shop;

import com.member.shop.domain.SysBizUserInvite;
import com.member.shop.service.ISysBizUserInviteService;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户邀请Controller
 *
 * @author thomas
 * @date 2024-07-05
 */
@RestController
@RequestMapping("/shop/user/invite")
public class SysBizUserInviteController extends BaseController {
    @Resource
    private ISysBizUserInviteService sysBizUserInviteService;

    /**
     * 查询用户邀请列表
     */
    @PreAuthorize("@ss.hasPermi('user:invite:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizUserInvite sysBizUserInvite) {
        startPage();
        List<SysBizUserInvite> list = sysBizUserInviteService.selectVwSysBizUserInviteList(sysBizUserInvite);
        return getDataTable(list);
    }

    /**
     * 导出用户邀请列表
     */
    @PreAuthorize("@ss.hasPermi('user:invite:export')")
    @Log(title = "用户邀请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizUserInvite sysBizUserInvite) {
        List<SysBizUserInvite> list = sysBizUserInviteService.selectVwSysBizUserInviteList(sysBizUserInvite);
        ExcelUtil<SysBizUserInvite> util = new ExcelUtil<SysBizUserInvite>(SysBizUserInvite.class);
        util.exportExcel(response, list, "用户邀请数据");
    }

    /**
     * 获取用户邀请详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:invite:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysBizUserInviteService.selectSysBizUserInviteById(id));
    }

    /**
     * 新增用户邀请
     */
    @PreAuthorize("@ss.hasPermi('user:invite:add')")
    @Log(title = "用户邀请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizUserInvite sysBizUserInvite) {
        return toAjax(sysBizUserInviteService.insertSysBizUserInvite(sysBizUserInvite));
    }

    /**
     * 修改用户邀请
     */
    @PreAuthorize("@ss.hasPermi('user:invite:edit')")
    @Log(title = "用户邀请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizUserInvite sysBizUserInvite) {
        return toAjax(sysBizUserInviteService.updateSysBizUserInvite(sysBizUserInvite));
    }

    /**
     * 删除用户邀请
     */
    @PreAuthorize("@ss.hasPermi('user:invite:remove')")
    @Log(title = "用户邀请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizUserInviteService.deleteSysBizUserInviteByIds(ids));
    }
}
